package com.uchedao.vehicledetection.config;


import android.content.Context;

import com.uchedao.vehicledetection.application.UCheDaoApplication;

/**
 * Created by zhengxizhen on 15/8/17.
 */
public class UserInfoManager {

    private final static String TN = "UchedaoUserInfoManager";

    /**
     * 用户凭证，所以需要用户操作的接口需要值的参数
     */
    public final static String PASS_PORT = "passport";
    /**
     * 登录状态
     */
    public final static String STATE = "state";

    public final static String USER_ID = "user_id";
    public final static String USERNAME = "username";
    public final static String CITY = "city_name";
    public final static String LEVEL = "follow_car_level";
    public final static String COMPANY = "company_name";
    public final static String MOBILE = "mobile";
    public final static String PASSWORD = "password";
    //    id	帐户ID
    //    amount	总金额
    //    available_amount	可用金额
    //    freeze_amount	交结金额
    public final static String AMOUNT = "amount";
    public final static String AVAILABLE_AMOUNT = "available_amount";
    public final static String FREEZE_AMOUNT = "freeze_amount";

    public static void saveAMOUNT(String port) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(AMOUNT, port).commit();
    }

    public static String getAMOUNT() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(AMOUNT, "0");
    }

    public static void saveAVAILABLE_AMOUNT(String port) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(AVAILABLE_AMOUNT, port).commit();
    }

    public static String getAVAILABLE_AMOUNT() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(AVAILABLE_AMOUNT, "0");
    }

    public static void saveFREEZE_AMOUNT(String port) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(FREEZE_AMOUNT, port).commit();
    }

    public static String getFREEZE_AMOUNT() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(FREEZE_AMOUNT, "0");
    }

    public static void saveSTATE(boolean state) {
        if (!state) {
            saveAMOUNT("0");
            saveAVAILABLE_AMOUNT("0");
            saveFREEZE_AMOUNT("0");
        }
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putBoolean(STATE, state).commit();
    }

    public static boolean getSTATE() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getBoolean(STATE, false);
    }

    public static boolean getSTATE(Context context) {
        return context.getSharedPreferences(TN, 0).getBoolean(STATE, false);
    }

    public static void savePASS_PORT(String port) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(PASS_PORT, port).commit();
    }

    public static String getPASS_PORT() {
        return getSTATE() ? UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(PASS_PORT, "") : "";
    }

    public static void saveUSER_ID(String id) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(USER_ID, id).commit();
    }

    public static String getUSER_ID() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(USER_ID, "");
    }

    public static void saveUSERNAME(String name) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(USERNAME, name).commit();
    }

    public static String getUSERNAME() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(USERNAME, "");
    }

    public static String getUSERNAME(Context context) {
        return context.getSharedPreferences(TN, 0).getString(USERNAME, "");
    }

    public static void saveCity(String city) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(CITY, city).commit();
    }

    public static String getCity() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(CITY, "");
    }

    public static void saveLevel(String level) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(LEVEL, level).commit();
    }

    public static String getLevel() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(LEVEL, "");
    }

    public static void saveCompany(String company) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(COMPANY, company).commit();
    }

    public static String getCompany() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(COMPANY, "");
    }

    public static void saveMOBILE(String name) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(MOBILE, name).commit();
    }

    public static String getMOBILE() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(MOBILE, "");
    }

    public static String getMOBILE(Context context) {
        return context.getSharedPreferences(TN, 0).getString(MOBILE, "");
    }

    public static void savePASSWORD(String pwd) {
        UCheDaoApplication.getContext().getSharedPreferences(TN, 0).edit().putString(PASSWORD, pwd).commit();
    }

    public static String getPASSWORD() {
        return UCheDaoApplication.getContext().getSharedPreferences(TN, 0).getString(PASSWORD, "");
    }
}
